#comments-start - More Info Dialog
[SCRIPT NAME]Move Files To Folder
Description:
    - Moves file(s) from the source location to the target desitionation.

Arguments:
    - Arg1: Folder to move files from (Required) - e.g. C:\MyFiles
    - Arg2: Folder to move files to (Required) - e.g. C:\MyFiles2
    - Arg3: Filter for files [Optional]
        - By default, all files are moved to the folder.
        - Example:
            - Specify *.txt to move only .txt files
    - Arg4: Overwrite existing files flag [Optional]
        - Options: (Combining values is allowed. e.g. 9 would give you functionality from both 1 & 8)
            - 0 = Do not overwrite existing files (Default)
            - 1 = Overwrite existing files
            - 8 = Create destination directory structure if it doesn't exist.
    - Arg5: Rename moved files [Optional]
        - Default is same name as source file
        - Examples: Old_*, *.*_Old, *.doc, *_Old
#comments-end - More Info Dialog
#include <Include\WinClickPro.au3>
#include <Include\File.au3>
#include <Include\Misc.au3>

Func Main()
	Local $sSourceFolderPath = ""
	Local $sTargetFolderPath = ""
	Local $sFileName = "*" ; Default is all
	Local $sOverwriteFlag = 0 ; Default is to not overwrite
	Local $sNewFileName = "*" ; Default is same name as source file

	;
	; This script has 2 required argument and 3 optional.
	;
	If $CmdLine[0]  < 2 Then
		_DisplayErrorAndExit("Invalid argument count detected!" & @LF & "Count: " & $CmdLine[0])
	EndIf

	$sSourceFolderPath = $CmdLine[1];
	$sTargetFolderPath = $CmdLine[2];

	;
	; Did the user specify the optional file name?
	;
	If $CmdLine[0] > 2 Then
		$sFileName = $CmdLine[3]
		If $sFileName == "" Then
			$sFileName = "*" ; User passed in a blank Arg, reset to default.
		EndIf
	EndIf

;
	; Did the user specify an optional filter?
	;
	If $CmdLine[0] > 3 Then
		$sOverwriteFlag = $CmdLine[4]
		If $sOverwriteFlag == "" Then
			$sOverwriteFlag = 0 ; User passed in a blank Arg, reset to default.
		ElseIf $sOverwriteFlag <> 0 And $sOverwriteFlag <> 1 And $sOverwriteFlag <> 8 And $sOverwriteFlag <> 9 Then
			_DisplayErrorAndExit("Overwrite flag is unexpected value!" & @LF & "Value: " & $sOverwriteFlag)
		EndIf
	EndIf

	;
	; Did the user specify the optional file name?
	;
	If $CmdLine[0] > 4 Then
		$sNewFileName = $CmdLine[5]
		If $sNewFileName == "" Then
			$sNewFileName = "*" ; User passed in a blank Arg, reset to default.
		EndIf
	EndIf

	;
	; The source folder must exist. If not, inform user.
	;
	If Not FileExists($sSourceFolderPath) Then
		_DisplayErrorAndExit("Folder does not exist!" & @LF & "Folder: " & $sSourceFolderPath)
	EndIf

	;
	; The destination folder must exist if they aren't creating it on the fly.
	;
	If Not FileExists($sTargetFolderPath) And $sOverwriteFlag < 8 Then
		_DisplayErrorAndExit("Folder does not exist!" & @LF & "Folder: " & $sTargetFolderPath)
	EndIf

	;
	; Make sure the folder path has a trailing \ if the user didn't provide it
	;
	If StringRight($sSourceFolderPath, 1) <> "\" Then
		$sSourceFolderPath = $sSourceFolderPath & "\"
	EndIf

	;
	; Make sure the folder path has a trailing \ if the user didn't provide it
	;
	If StringRight($sTargetFolderPath, 1) <> "\" Then
		$sTargetFolderPath = $sTargetFolderPath & "\"
	EndIf

	FileMove ($sSourceFolderPath & $sFileName, $sTargetFolderPath & $sNewFileName, $sOverwriteFlag)
EndFunc

Main()
Exit @error